package com.cr.web.controller.api;

import com.cr.business.domain.dto.app.ProducerEditParam;
import com.cr.business.domain.dto.app.ProducerListParam;
import com.cr.business.service.ITbProducerInfoService;
import com.cr.common.core.controller.BaseController;
import com.cr.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 生产人管理
 */
@RestController
@RequestMapping("api/producer")
public class ProducerInfoController extends BaseController {

    @Resource
    private ITbProducerInfoService tbProducerInfoService;

    /**
     * 查询生产人信息列表
     */
    @GetMapping("/list")
    public AjaxResult list(@Valid ProducerListParam param){
        return AjaxResult.success(tbProducerInfoService.getAppList(param));
    }

    /**
     * 查询生产人信息
     * @param producerId 生产人ID
     */
    @GetMapping("/get/{producerId}")
    public AjaxResult get(@PathVariable("producerId") String producerId) {
        return AjaxResult.success(tbProducerInfoService.selectTbProducerInfoByProducerId(producerId));
    }

    /**
     * 新增生产人信息
     * @param param 参数
     */
    @PostMapping("/add")
    public AjaxResult add(@Valid ProducerEditParam param) {
        return toAjax(tbProducerInfoService.insertTbProducerInfo(param));
    }

    /**
     * 修改生产人信息
     * @param producerId 生产人ID
     * @param param 生产人信息
     */
    @PutMapping("/update/{producerId}")
    public AjaxResult update(@PathVariable("producerId") String producerId, @Valid ProducerEditParam param) {
        param.setId(producerId);
        return toAjax(tbProducerInfoService.updateTbProducerInfo(param));
    }

    /**
     * 删除生产人信息
     * @param producerId 生产人ID
     */
    @DeleteMapping("/delete/{producerId}")
    public AjaxResult delete(@PathVariable("producerId") String producerId) {
        return toAjax(tbProducerInfoService.deleteTbProducerInfoByProducerId(producerId));
    }

    /**
     * 获取生产人下拉数据
     */
    @GetMapping("/getOptionData")
    public AjaxResult getAppOptionData(){
        return AjaxResult.success(tbProducerInfoService.getAppOptionData());
    }
}
